package com.example.coffeejava.Controller;

import com.example.coffeejava.Dto.InfoDto;
import com.example.coffeejava.Dto.PageResult;
import com.example.coffeejava.Dto.Result;
import com.example.coffeejava.Entity.Info;
import com.example.coffeejava.Entity.Shop;
import com.example.coffeejava.Entity.Type;
import com.example.coffeejava.Service.InfoService;
import com.example.coffeejava.Service.TypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/info")
public class InfoController {
    @Resource
    private TypeService typeService;
    @Resource
    private InfoService infoService;
    @RequestMapping("/list")
    public Result list(Integer pageNum,Integer pageSize,String keyword){
        PageResult pageResult=infoService.getlist(pageNum,pageSize,keyword);
        return Result.ok(pageResult);
    }
    @PostMapping("/addorupdate")
    public Result addorupdate(@RequestBody InfoDto infoDto) {
      return infoService.addorUpdate(infoDto);
    }
    @GetMapping("/uporoff")
    public Result uporoff(String id){
        return infoService.uporoff(id);
    }
    @GetMapping("/delete")
    public Result delete(String id){
        infoService.removeById(id);
        return Result.ok("成功");
    }
    @GetMapping("/coffeetop4")
    public Result coffeetop4(){
        return infoService.coffeetop4();
    }
    @GetMapping("/detail")
    public Result detail(String id){
        Info info=infoService.getById(id);
        Type type=typeService.getById(info.getTypeId());
        info.setTypeName(type.getName());
        return Result.ok(info);
    }



}
